package com.ysm.smfu.food;

import android.support.v7.app.AlertDialog;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.widget.ImageView;
import android.widget.TextView;

import com.ysm.smfu.R;
import com.ysm.smfu.activity.BaseActivity;
import com.ysm.smfu.food.presenter.FoodTuiKuanPerSenterImp;
import com.ysm.smfu.food.presenter.FoodTuiKuanPersenter;
import com.ysm.smfu.food.view.FoodTuikuanDetailView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/4/6.
 */
public class FoodTuiKuanDetailActivity extends BaseActivity implements FoodTuikuanDetailView {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.title)
    TextView title;

    @BindView(R.id.tuiKuanNum)
    TextView tuiKuanNum;

    @BindView(R.id.tuiKuanType)
    TextView tuiKuanType;

    @BindView(R.id.tuiKuanTime)
    TextView tuiKuanTime;

    @BindView(R.id.tuiKuanImg1)
    ImageView tuiKuanImg1;
    @BindView(R.id.tuiKuanImg2)
    ImageView tuiKuanImg2;
    @BindView(R.id.tuiKuanImg3)
    ImageView tuiKuanImg3;

    @BindView(R.id.shiErText)
    TextView shiErText;
    private FoodTuiKuanPersenter perSenter;

    @Override
    protected void initViews() {
        super.initViews();
        setContentView(R.layout.activity_foodtuikuandetail);
        ButterKnife.bind(this);
        title.setText("退款详情");
        perSenter = new FoodTuiKuanPerSenterImp(this);
        perSenter.showPage();
    }

    @Override
    public void showMoneyAndType(String money, String type, String isHas) {
        tuiKuanNum.setText(money + "元");
        tuiKuanType.setText(type);
        tuiKuanTime.setText(isHas);
    }

    @Override
    public void showFlow(int flow) {
        if (flow == 1) {
            tuiKuanImg1.setImageResource(R.drawable.tuikuan_has);
        } else if (flow == 2) {
            tuiKuanImg1.setImageResource(R.drawable.tuikuan_has);
            tuiKuanImg2.setImageResource(R.drawable.tuikuan_has_line);
        } else if (flow == 3) {
            tuiKuanImg1.setImageResource(R.drawable.tuikuan_has);
            tuiKuanImg2.setImageResource(R.drawable.tuikuan_has_line);
            tuiKuanImg3.setImageResource(R.drawable.tuikuan_has_line);
        }
    }

    @Override
    public void setNumber(String number) {
        String formatString = String.format(getResources().getString(R.string.tuikuanText), number);
        int index = formatString.indexOf("号");
        int index2 = formatString.indexOf("服");
        SpannableStringBuilder builder = new SpannableStringBuilder(formatString);
        ForegroundColorSpan number_color = new ForegroundColorSpan(getResources().getColor(R.color.number_color));
        ForegroundColorSpan number_color2 = new ForegroundColorSpan(getResources().getColor(R.color.number_color));
        builder.setSpan(number_color, index + 1, index + 1 + number.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(number_color2, index2 + 1, index2 + 12, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        shiErText.setText(builder);
    }

    @Override
    public void showError(String msg) {
        new AlertDialog.Builder(this).setMessage(msg).setNegativeButton("确认", null);
    }

    @OnClick(R.id.back)
    public void onclick() {
        finish();
    }
}
